#!/bin/bash

############################################################################
#
# 远程执行该脚本，请在命令行中直接执行以下命令：
#
#   curl -sSL https://gitee.com/tay3223/biubiubiu/raw/master/centos7-install-php80-phpipam.sh | /bin/bash
#
#
############################################################################

#官网地址：https://phpipam.net/news/phpipam-installation-on-centos7-php8-nginx/


cat <<\EOF >> /etc/environment
LC_ALL=zh_CN.utf-8
LANG=zh_CN.utf-8
EOF


#sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
#yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm

yum -y install yum-utils
yum-config-manager --disable 'remi-php*'
yum-config-manager --enable remi-php80

yum install -y nginx \
    mariadb-server \
    git  \
    php \
    php-cli \
    php-gd \
    php-fpm \
    php-common \
    php-ldap \
    php-pdo \
    php-mysqlnd \
    php-pear \
    php-snmp \
    php-xml \
    php-mbstring \
    php-mcrypt \
    php-gmp

sed -i 's/^;date.timezone/date.timezone = Asia\/Shanghai/' /etc/php.ini

systemctl start php-fpm
systemctl enable php-fpm
systemctl status php-fpm

cat <<\EOF > /etc/nginx/conf.d/phpipam.conf
server {
    # listen on 80 as default server
    listen       80;
    server_name  _;

    # root directory
    root         /var/www/html;

    # logs
    access_log  /var/log/nginx/phpipam.access.log;
    error_log  /var/log/nginx/phpipam.error.log;

    # root location
    location / {
        try_files $uri $uri/ =404;
        index index.php;

        error_page 500 /app/error/index.php;
        error_page 404 /app/error/index.php;
        error_page 403 /app/error/index.php;
    }

    # php-fpm
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        try_files      $uri $uri/ index.php = 404;
	fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    # dont log this
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
         expires max;
         log_not_found off;
    }
}
EOF


systemctl start nginx
systemctl enable nginx
systemctl status nginx



#剩下的就是MariaDB相关的内容，还没写完，参见官网1.4章节：https://phpipam.net/news/phpipam-installation-on-centos7-php8-nginx/
